package com.utils;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.fgsort.FileArrayProvider;

public class Files {

	public List<String> getSymbolFile(String sSymbolFile)	{

		List<String> lstSymbolFile = new ArrayList<String>();
		FileArrayProvider fap = new FileArrayProvider();
		try {
			///read plc src file
			String[] lines;
			lines = fap.readLines(sSymbolFile);

			///finds valid function groups and stores in array
			for (String line : lines) {
				if (line.substring(28, 30).trim().equals("I") || 
					line.substring(28, 30).trim().equals("IB") ||	
					line.substring(28, 30).trim().equals("IW") ||
					line.substring(28, 30).trim().equals("ID") ||
					line.substring(28, 30).trim().equals("Q") ||
					line.substring(28, 30).trim().equals("QB") ||
					line.substring(28, 30).trim().equals("QW") ||
					line.substring(28, 30).trim().equals("QD"))	{

					lstSymbolFile.add(line.substring(4, 27).trim());	///symbol name
					lstSymbolFile.add(line.substring(28, 39).trim());	///io number
					lstSymbolFile.add(line.substring(40, 49).trim());	///type

					if (line.length() > 51)	{
						if (!line.substring(50, line.length()-1).trim().isEmpty())
							lstSymbolFile.add(line.substring(50, line.length()-1).trim());	///comment
						else 
							lstSymbolFile.add("");
					}
					else 
						lstSymbolFile.add("");
				}
			}

//			int cnt = 0;
//			for (String str : lstSymbolFile){
//				if (cnt < 4)	{				
//					System.out.print(str+",");
//					cnt++;
//				}
//				else	{
//					System.out.println();
//					System.out.print(str+",");
//					cnt = 0;
//				}
//			}

		} catch (IOException e) {
			e.printStackTrace();
		}

		return lstSymbolFile;

	}
}
